﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Interface_Tier;
using Transfer_Object_Tier;

namespace eSolution_HRMSS.Winforms
{
    public partial class FR_NoiDaoTao : DevExpress.XtraEditors.XtraForm
    {
        //khai bao interface
        IDIC_SCHOOLData _IDIC_SCHOOLData;
        HRMSS_Ultil util = new HRMSS_Ultil();
        public delegate void updatelist();
        public updatelist truyentinhieu;
        public FR_NoiDaoTao()
        {
            InitializeComponent();
        }

        private void FR_Hospital_Load(object sender, EventArgs e)
        {
            //dang ky interface
            _IDIC_SCHOOLData = (IDIC_SCHOOLData)Activator.GetObject(typeof(IDIC_SCHOOLData), util.ChuoiDIC_SCHOOLDATA);

            //load thu thoi nha nen lam theo de test thu coi lay du lieu dc ko
            load_ds_bv();
        }

        private void load_ds_bv()
        {
            grddsbv.DataSource = _IDIC_SCHOOLData.DIC_SCHOOL_GetList().Tables[0];
        }

        private void btthemmoi_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            FR_Add_School add_bv = new FR_Add_School(false);
            add_bv.truyentinhieu = new FR_Add_School.updatelist(load_ds_bv);
            add_bv.ShowDialog(this);
        }

        private void btsua_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string ma = dsbangcap.GetFocusedDataRow()[0].ToString();
            FR_Add_School add_bv = new FR_Add_School(true, ma);
            add_bv.truyentinhieu = new FR_Add_School.updatelist(load_ds_bv);
            add_bv.ShowDialog(this);
        }

        private void btxoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (MessageBox.Show(util.Xacnhanxoa, "Xác nhận thông tin", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                foreach (int selectedindex in dsbangcap.GetSelectedRows())
                {
                    string ma = ((DataRowView)dsbangcap.GetRow(selectedindex))[0].ToString();

                    if (_IDIC_SCHOOLData.DIC_SCHOOL_Delete(ma) < 0)
                    {
                        MessageBox.Show(util.Loithaotac);
                    }
                }
                load_ds_bv();
            }
        }

        private void btnaplai_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            load_ds_bv();
        }

        private void btin_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void btxuat_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            saveFileDialog1.Filter = "Excel File|*.xls";
            saveFileDialog1.Title = "Xuất danh sách ra file MS Excel";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if (saveFileDialog1.FileName.Length > 0)
                {
                    grddsbv.ExportToXls(saveFileDialog1.FileName.ToString());
                }
            }
        }

        private void grddsbv_DoubleClick(object sender, EventArgs e)
        {
            string ma = dsbangcap.GetFocusedDataRow()[0].ToString();
            FR_Add_School add_bv = new FR_Add_School(true, ma);
            add_bv.truyentinhieu = new FR_Add_School.updatelist(load_ds_bv);
            add_bv.ShowDialog(this);
        }
        
        private void FR_Hospital_FormClosing(object sender, FormClosingEventArgs e)
        {
            truyentinhieu();
        }
    }
}